package com.example.demo.controller;

import com.example.demo.controller.dto.AAndB;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/backend")
public class MainController {

    //get请求
    @GetMapping("/get")
    public String get(Integer a,String b) {
        System.out.println(a);
        System.out.println(b);
        return "success";
    }

    //post-formData请求
    @PostMapping("/post-formData")
    public String postFormData(Integer a,String b) {
        System.out.println(a);
        System.out.println(b);
        return "success";
    }

    //post-formData请求
    @PostMapping("/post-formData-list")
    public String postFormDataHasList(Integer a,String b,int[] c) {
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        return "success";
    }

    //post-json请求,通过object对象接收
    @PostMapping("/post-json")
    public String postJson(@RequestBody Object data) {
        System.out.println(data);
        return "success";
    }

    //post-json请求,通过自定义对象接收
    @PostMapping("/post-json-custom")
    public String postJson(@RequestBody AAndB data) {
        System.out.println(data);
        return "success";
    }

    //post-urlencode请求,直接通过包装类型接受
    @PostMapping("/post-urlencode")
    //一般使用RequestParam会进行特别定义,比如这个参数有别的名称,或者设定默认值
    // public String postJson(@RequestParam Integer a,@RequestParam String b) {
    //不使用也完全没问题
    public String postJson(Integer a,String b) {
        System.out.println(a);
        System.out.println(b);
        return "success";
    }
}
